package com.woniu.his.controller;

import com.woniu.his.entity.HospitalizationInfo;
import com.woniu.his.service.InhospitalService;
import com.woniu.his.service.impl.InhospitalServiceImpl;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;
import java.util.Map;

/*
住院部
 */
@Controller
@RequestMapping("/inhospital")
public class InhospitalController {
    @Autowired
    InhospitalService inhospitalService = new InhospitalServiceImpl();

    /*
    显示住院部主页面
     */
    @RequestMapping("index")
    @RequiresRoles("住院部")
    public String inhospitalShow() {
        return "forward:queryInhospitalInfo";
    }

    /*
    查询住院患者信息显示
     */
    @RequestMapping("queryInhospitalInfo")
    @RequiresRoles("住院部")
    public String showInhospitalInfo(ModelMap modelMap) {

        List<Map> hospitalizationInfos = inhospitalService.queryAllInhospitalInfo();
        modelMap.addAttribute("hospitalizationInfos", hospitalizationInfos);
        System.out.println("查询出的已住院患者数组: " + hospitalizationInfos);
        return "inhospital-patients";
    }

    /*
    药品申请
     */
    @RequestMapping(value = "drugApply", method = RequestMethod.GET)
    @RequiresRoles("住院部")
    public String drugApply(String medicalId, String patientName, ModelMap modelMap) {
        modelMap.addAttribute("medicalId", medicalId);
        modelMap.addAttribute("patientName", patientName);
        System.out.println("获取到的medicalId=" + medicalId);
        return "inhospital-drug-apply";
    }
}
